//
//  WebViewJSUtil.m
//  GuiJuWo
//
//  Created by chenguibang on 16/4/6.
//  Copyright © 2016年 chenguibang. All rights reserved.
//

#import "WebViewJSUtil.h"

@implementation WebViewJSUtil
+(NSDictionary *)splitUrl:(NSString *)url{
    
    return (NSDictionary*)[url mj_JSONObject];
    
//    NSString *urlString =[url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    NSArray *urlComps = [urlString componentsSeparatedByString:@"&"];
//    NSArray *arrFucnameAndParameter;
//    
//    
//    return urlComps;

}

+(NSString *)getFunctionName:(NSString *)url{
    
    
    
    
    NSDictionary *firstSplitDict = [self splitUrl:url];
    NSString *functionName = firstSplitDict[@"function"] == [NSNull null]? nil:firstSplitDict[@"function"];
    
    return functionName;
//    if([firstSplitArr count])
//    {
//        NSString *functionstr = firstSplitArr[0];
//        if ([functionstr rangeOfString:@"function"].location != NSNotFound) {
//            NSArray *functionArr = [functionstr componentsSeparatedByString:@":"];
//            return [functionArr lastObject];
//        }else{
//            return nil;
//        }
//    }else{
//        return nil;
//    }
//    return nil;
    
}

+(NSString *)getParamters:(NSString *)url{
    NSArray *firstSplitArr = [self splitUrl:url];
    if([firstSplitArr count])
    {
        NSString *functionstr = firstSplitArr[1];
        if ([functionstr rangeOfString:@"paramters"].location != NSNotFound) {
            NSArray *functionArr = [functionstr componentsSeparatedByString:@":"];
            return [functionArr lastObject];
        }else{
            return nil;
        }
    }else{
        return nil;
    }
    return nil;
}
@end
